﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using Reborn_WorldServer;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_FreezingWinds : Buff
    {
        private int AtkSpeedPercentAdded = 10;

        public Spell_FreezingWinds()
        {
            minutesLeft = 3;
        }
        override public void Resume(CreatureBase targetCreatureBase, SpellIcon _spellIcon, int timeRemaining, int castLevel, int castCharacterID, int castInt, int castWis, int optionalValue, string xmlData)
        {
            minutesLeft = timeRemaining;
            base.Resume(targetCreatureBase, _spellIcon, timeRemaining, castLevel, castCharacterID, castInt, castWis, optionalValue, xmlData);

            AtkSpeedPercentAdded = 20 + SkillManager.AdjustForCombat(castLevel / 3, 0, 0);

            TargetCreatureBase.MeleeSpeedPercentModifier = TargetCreatureBase.MeleeSpeedPercentModifier + AtkSpeedPercentAdded;

            spellTimer.Start();
        }

        override public bool tryResist(SpellIcon _spellIcon, int castLevel, int castInt, int castWis, CreatureBase targetCreatureBase)
        {
            int penetration = SkillManager.AdjustForCombat(castLevel, 0, castInt);

            int resist = targetCreatureBase.getResist(_spellIcon.Skill);

            int result = Managers.GameHandler.random.Next(1, penetration + resist + 1);
            if (result > penetration)
                return true;

            return false;
        }

        public void Cast(CreatureBase myCreatureBase, int CastLevel, long CreatureGUID)
        {
            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCreatureBase, CastLevel, CreatureGUID, true, out MapItemsWithin12) == false)
                return;

            AtkSpeedPercentAdded = 20 + SkillManager.AdjustForCombat(CastLevel / 2, 0, 0);

            TargetCreatureBase.MeleeSpeedPercentModifier = TargetCreatureBase.MeleeSpeedPercentModifier + AtkSpeedPercentAdded;
            TargetCreatureBase.buffManager.UpdateBuffs();

            //Start Spell Timer
            spellTimer.Start();
        }
        public override void RemoveSpell(bool updateBuffs, bool sendMessage)
        {
            base.RemoveSpell(updateBuffs, sendMessage);
            TargetCreatureBase.MeleeSpeedPercentModifier = TargetCreatureBase.MeleeSpeedPercentModifier - AtkSpeedPercentAdded;
        }
    }
}
